home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / gridex / frmshowf.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-01-02  |  7.2 KB  |  241 lines

  1. VERSION 5.00
  2. Begin VB.Form frmShowfields 
  3.    BorderStyle     =   3  'Fixed Dialog
  4.    Caption         =   "Show Fields"
  5.    ClientHeight    =   3810
  6.    ClientLeft      =   2175
  7.    ClientTop       =   2145
  8.    ClientWidth     =   7710
  9.    Icon            =   "frmShowfields.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   3810
  14.    ScaleWidth      =   7710
  15.    ShowInTaskbar   =   0   'False
  16.    StartUpPosition =   2  'CenterScreen
  17.    Begin VB.CommandButton cmdOK 
  18.       Caption         =   "OK"
  19.       Height          =   330
  20.       Left            =   6555
  21.       TabIndex        =   9
  22.       Top             =   450
  23.       Width           =   1020
  24.    End
  25.    Begin VB.CommandButton cmdCancel 
  26.       Caption         =   "Cancel"
  27.       Height          =   375
  28.       Left            =   6555
  29.       TabIndex        =   8
  30.       Top             =   840
  31.       Width           =   1035
  32.    End
  33.    Begin VB.CommandButton cmdDown 
  34.       Caption         =   "Move Down"
  35.       Height          =   345
  36.       Left            =   5280
  37.       TabIndex        =   7
  38.       Top             =   3345
  39.       Width           =   1170
  40.    End
  41.    Begin VB.CommandButton cmdUp 
  42.       Caption         =   "Move Up"
  43.       Height          =   345
  44.       Left            =   4020
  45.       TabIndex        =   6
  46.       Top             =   3360
  47.       Width           =   1140
  48.    End
  49.    Begin VB.CommandButton cmdRemove 
  50.       Caption         =   "<- Remove"
  51.       Height          =   345
  52.       Left            =   2745
  53.       TabIndex        =   5
  54.       Top             =   930
  55.       Width           =   1125
  56.    End
  57.    Begin VB.CommandButton cmdAdd 
  58.       Caption         =   "Add ->"
  59.       Height          =   345
  60.       Left            =   2745
  61.       TabIndex        =   4
  62.       Top             =   480
  63.       Width           =   1125
  64.    End
  65.    Begin VB.ListBox lstVisible 
  66.       Height          =   2790
  67.       Left            =   3990
  68.       TabIndex        =   1
  69.       Top             =   480
  70.       Width           =   2415
  71.    End
  72.    Begin VB.ListBox lstAvail 
  73.       Height          =   2790
  74.       Left            =   180
  75.       TabIndex        =   0
  76.       Top             =   495
  77.       Width           =   2415
  78.    End
  79.    Begin VB.Label lblcaption 
  80.       Caption         =   "Show these fields in this order:"
  81.       Height          =   255
  82.       Index           =   1
  83.       Left            =   4035
  84.       TabIndex        =   3
  85.       Top             =   180
  86.       Width           =   2460
  87.    End
  88.    Begin VB.Label lblcaption 
  89.       Caption         =   "Available fields:"
  90.       Height          =   255
  91.       Index           =   0
  92.       Left            =   195
  93.       TabIndex        =   2
  94.       Top             =   225
  95.       Width           =   1800
  96.    End
  97. Attribute VB_Name = "frmShowfields"
  98. Attribute VB_GlobalNameSpace = False
  99. Attribute VB_Creatable = False
  100. Attribute VB_PredeclaredId = True
  101. Attribute VB_Exposed = False
  102. Option Explicit
  103. Option Compare Text
  104. Dim m_OK As Boolean
  105. Public Function ShowFields(gr As GridEX) As Boolean
  106. Dim c As Column
  107. Dim strName As String
  108. Dim i As Integer
  109. Dim db As Database
  110.     m_OK = False
  111.     Set db = OpenDatabase(gr.DatabaseName)
  112.     For i = 1 To gr.Columns.Count
  113.         Set c = gr.Columns.ItemByPosition(i)
  114.         strName = c.Tag
  115.         If Not c.Visible Then
  116.             lstAvail.AddItem strName
  117.             lstAvail.ItemData(lstAvail.NewIndex) = c.Index
  118.         Else
  119.             lstVisible.AddItem strName
  120.             lstVisible.ItemData(lstVisible.NewIndex) = c.Index
  121.         End If
  122.     Next
  123.     On Error Resume Next
  124.     lstAvail.ListIndex = 0
  125.     lstVisible.ListIndex = 0
  126.     Show 1
  127.     If m_OK Then
  128.         ShowFields = True
  129.         For i = 0 To lstAvail.ListCount - 1
  130.             Set c = gr.Columns(lstAvail.ItemData(i))
  131.             c.Visible = False
  132.         Next
  133.         For i = 0 To lstVisible.ListCount - 1
  134.             Set c = gr.Columns(lstVisible.ItemData(i))
  135.             c.Visible = True
  136.             c.ColPosition = i + 1
  137.         Next
  138.     End If
  139.     Unload Me
  140. End Function
  141. Private Sub cmdAdd_Click()
  142. Dim ColIndex As Integer
  143. Dim ColText As String
  144. Dim lngListindex As Long
  145. Dim c As Column
  146.     lstAvail.SetFocus
  147.     If lstAvail.ListIndex = -1 Then Exit Sub
  148.     lngListindex = lstAvail.ListIndex
  149.     ColIndex = lstAvail.ItemData(lngListindex)
  150.     ColText = lstAvail.Text
  151.     lstAvail.RemoveItem lngListindex
  152.     lstVisible.AddItem ColText
  153.     lstVisible.ItemData(lstVisible.NewIndex) = ColIndex
  154.     If lstAvail.ListCount - 1 >= lngListindex Then
  155.         lstAvail.ListIndex = lngListindex
  156.     Else
  157.         lstAvail.ListIndex = lngListindex - 1
  158.     End If
  159.     lstVisible.ListIndex = lstVisible.NewIndex
  160.     EnableButtons
  161. End Sub
  162. Private Sub EnableButtons()
  163.     cmdAdd.Enabled = (lstAvail.ListIndex <> -1)
  164.     cmdRemove.Enabled = (lstVisible.ListIndex <> -1)
  165.     cmdUp.Enabled = (lstVisible.ListIndex > 0)
  166.     cmdDown.Enabled = (lstVisible.ListIndex < lstVisible.ListCount - 1)
  167. End Sub
  168. Private Sub cmdCancel_Click()
  169.     Hide
  170. End Sub
  171. Private Sub cmdDown_Click()
  172. Dim ColIndex As Long
  173. Dim ColText As String
  174. Dim lngListindex As Long
  175.     If lstVisible.ListIndex = -1 Or lstVisible.ListIndex = lstVisible.ListCount - 1 Then Exit Sub
  176.     With lstVisible
  177.         lngListindex = .ListIndex
  178.         ColText = .Text
  179.         ColIndex = .ItemData(lngListindex)
  180.         .RemoveItem lngListindex
  181.         lngListindex = lngListindex + 1
  182.         .AddItem ColText, lngListindex
  183.         .ItemData(.NewIndex) = ColIndex
  184.         .ListIndex = .NewIndex
  185.         .SetFocus
  186.     End With
  187.     EnableButtons
  188. End Sub
  189. Private Sub cmdOK_Click()
  190.     m_OK = True
  191.     Hide
  192. End Sub
  193. Private Sub cmdRemove_Click()
  194. Dim ColIndex As Integer
  195. Dim ColText As String
  196. Dim lngListindex As Long
  197. Dim c As Column
  198.     lstVisible.SetFocus
  199.     If lstVisible.ListIndex = -1 Then Exit Sub
  200.     lngListindex = lstVisible.ListIndex
  201.     ColIndex = lstVisible.ItemData(lngListindex)
  202.     ColText = lstVisible.Text
  203.     lstVisible.RemoveItem lngListindex
  204.     lstAvail.AddItem ColText
  205.     lstAvail.ItemData(lstAvail.NewIndex) = ColIndex
  206.     If lstVisible.ListCount - 1 >= lngListindex Then
  207.         lstVisible.ListIndex = lngListindex
  208.     Else
  209.         lstVisible.ListIndex = lngListindex - 1
  210.     End If
  211.     lstAvail.ListIndex = lstAvail.NewIndex
  212.     EnableButtons
  213. End Sub
  214. Private Sub cmdUp_Click()
  215. Dim ColIndex As Long
  216. Dim ColText As String
  217. Dim lngListindex As Long
  218.     If lstVisible.ListIndex <= 0 Then Exit Sub
  219.     With lstVisible
  220.         lngListindex = .ListIndex
  221.         ColText = .Text
  222.         ColIndex = .ItemData(lngListindex)
  223.         .RemoveItem lngListindex
  224.         If lngListindex > 0 Then lngListindex = lngListindex - 1
  225.         .AddItem ColText, lngListindex
  226.         .ItemData(.NewIndex) = ColIndex
  227.         .ListIndex = .NewIndex
  228.         .SetFocus
  229.     End With
  230.     EnableButtons
  231. End Sub
  232. Private Sub lstAvail_DblClick()
  233.     cmdAdd_Click
  234. End Sub
  235. Private Sub lstVisible_Click()
  236.     EnableButtons
  237. End Sub
  238. Private Sub lstVisible_DblClick()
  239.     cmdRemove_Click
  240. End Sub
  241.